import config from "./config";
const request = (opitons) => {
	return new Promise((resolve, reject) => {
		if (opitons.method == "GET") {
			uni.request({
				// url: `${config.host.api}${opitons.url}`,
				url: `${opitons.url}`,
				data: opitons.data,
				method: opitons.method,
				success: (res) => {
					// alert('request - success: ' +JSON.stringify(res))
					return resolve(res.data)
				},
				fail: (error) => {
					alert('request - error: ' +JSON.stringify(error))
					return reject(error)
				},
				complete: (info)=> {
				}
			});
		}
		if (opitons.method == "POST") {
			uni.request({
				// url: `${config.host.api}${opitons.url}`,
				url: `${opitons.url}`,
				data: opitons.data,
				method: opitons.method,
				header: {
					'content-type': 'application/json'
				},
				success: (res) => {
					return resolve(res.data)
				},
				fail: (error) => {
					alert('request - error: ' +JSON.stringify(error))
					return reject(error)
				},
				complete: (info)=> {
				}
			});
		}
	})
}

export default request